package com.gzhryc.shared_device.oem.code.statistics.dao;

import com.gzhryc.jdbc.BaseDao;
import com.gzhryc.jdbc.Conditions;
import com.gzhryc.jdbc.Query;
import com.gzhryc.shared_device.oem.code.statistics.dao.db.ProjectDayStatistics;
import com.gzhryc.shared_device.oem.code.statistics.dao.models.ProjectSumMoneyData;

import java.sql.SQLException;

public class ProjectDayStatisticsDao extends BaseDao<ProjectDayStatistics> {

    public ProjectDayStatisticsDao(String jdbcKey) {
        super(jdbcKey);
    }

    public ProjectSumMoneyData sumMoneyData(Conditions conditions) throws SQLException {
        String sql = "SELECT SUM(order_count) AS orderCount,SUM(order_money) AS orderMoney" +
                ",SUM(order_pay_money) AS orderPayMoney" +
                ",SUM(history_cancel_order_count) AS historyCancelOrderCount" +
                ",SUM(history_cancel_order_money) AS historyCancelOrderMoney" +
                ",SUM(history_refund_order_count) AS historyRefundOrderCount" +
                ",SUM(history_refund_order_money) AS historyRefundOrderMoney" +
                " FROM " + this.tableName;

        Query query = new Query(sql);
        query.appendSql(conditions.toSql(query.getParams(),true));
        return this.jdbcHelper.get(query,ProjectSumMoneyData.class);
    }
}
